package com.atde._04_structural_design_patterns.decorator;


/**
 * @BelongsProject: hsp_java_design_mode
 * @BelongsPackage: com.atde._04_structural_design_patterns.decorator
 * @Author: Del
 * @CreateTime: 2025-06-20  15:08
 * @Description: 装饰器模式 --- 装饰者
 * @Version: 1.0
 */
public class Decorator extends Drink{

    private final Drink drink;

    public Decorator(Drink drink) {
        this.drink = drink;
    }


    @Override
    public float cost() {
        return super.getPrice() + this.drink.cost();
    }

    public String getDes() {
        // 递归获取所有装饰者的描述，并拼接
        String description = drink.getDes() + "(" + drink.getPrice() + ")" + " + " + super.getDes() + "(" + super.getPrice() + ")";
        // 示例输出：
        // "LongBlack + Milk(2.0) + Chocolate(3.0)"
        return description + " = 总价：" + cost();
    }
}
